#!/usr/bin/env python
# -*- coding: utf-8 -*-

import getdata
import sys
import urllib2
try:
        import pygtk
        pygtk.require("2.0")
except:
        pass
try:
        import gtk
        import gtk.glade
except:
        sys.exit(1)

class HellowWorldGTK:
        

        def __init__(self):
                #Set the Glade file
                self.gladefile = "muh.glade"
                self.wTree = gtk.glade.XML(self.gladefile,"window1") 
                #Create our dictionay and connect it
                dic = { "on_toolbutton1_clicked" : self.button1_clicked,
                        "on_button3_clicked" : self.button3_clicked,
			"on_button4_clicked" : self.kaydet_clicked,
                        "on_window1_destroy" : gtk.main_quit }
                self.wTree.signal_autoconnect(dic)
                #self.label1= self.wTree.get_widget("label1")
                self.window1= self.wTree.get_widget("window1")
                self.button1= self.wTree.get_widget("toolbutton1")
                #self.scrolledwindow1= self.wTree.get_widget("scrolledwindow1")
                self.textview1= self.wTree.get_widget("textview1")
		self.vbox1= self.wTree.get_widget("vbox1")
                #self.calendar1= self.wTree.get_widget("calendar1")
                self.Result = gtk.TextBuffer()
                self.frame1=self.wTree.get_widget("frame1")
                self.frame2=self.wTree.get_widget("frame2")
                self.note1=self.wTree.get_widget("notebook1")
                self.button3= self.wTree.get_widget("button3")
                self.hbox2= self.wTree.get_widget("hbox2")
		self.cekno= self.wTree.get_widget("entry2")
		self.banka= self.wTree.get_widget("entry3")
		self.sube= self.wTree.get_widget("entry4")
		self.kesideci=self.wTree.get_widget("entry6")
		self.kesideyeri=self.wTree.get_widget("entry9")
		self.kesidetar=self.wTree.get_widget("entry7")
		self.hesapno=self.wTree.get_widget("entry5")
		self.tutar=self.wTree.get_widget("entry8")
		
		
		
                #self.textbuffer.set_text("bravo")
                self.textview1.set_buffer(self.Result)
                self.frame1.hide()
		self.frame2.hide()
                self.x=1
                #self.button1.set_label("TCMB den döviz bilgisi al ")
                #self.label1.set_label("  BUGÜN  ")
		self.buttonbilgi_clicked()
		getdata.cursor.execute("SET NAMES 'utf8'")
		getdata.cursor.execute("SET collation_connection = 'utf8_turkish_ci'")                                
                




        def kaydet_clicked(self, widget):
		getdata.cursor.execute( """insert into musteri (ad,soyad,tel,email) values (%s,%s,%s,%s) """, (self.cekno.get_text(),self.banka.get_text(),self.sube.get_text(),self.kesideci.get_text()))
                self.data = getdata.cursor.fetchall()
              #  self.fields = getdata.cursor.description()
		print self.data 
		#print self.fields
	
	def button1_clicked(self, widget):
		print "button1 clicked"
               

        def button3_clicked(self, widget):
                cpage=self.note1.get_current_page()
                self.button99 = gtk.Button("Hello World")
                self.hbox2.add(self.button99)
                self.button99.show()#self.note1.remove_page(cpage)
                self.table = gtk.Table(2, 2, True)
                self.button999 = gtk.Button("jjaaa")
                self.table.attach(self.button999, 0, 1, 0, 1)
                self.button999.show ()
                self.table.show()
                label = gtk.Label("Add page")
                self.note1.insert_page(self.table,label, -1)
	
	def buttonbilgi_clicked(self):
		# Create a 2x2 table
		
		self.table = gtk.Table(2, 2, True)
		self.vbox1.add(self.table)
		# Put the table in the main window
		#self.window1.add(table)
		# Create first button
		label222 = gtk.Label("button 1")
		# When the button is clicked, we call the "callback" method
		# with a pointer to "button 1" as its argument
		# button.connect("clicked", self.callback, "button 1")
		# Insert button 1 into the upper left quadrant of the table
		self.table.attach(label222,0,1,0,1)
		label222.show()
		# Create second button
		label223 = gtk.Label("button 2")
		# When the button is clicked, we call the "callback" method
		# with a pointer to "button 2" as its argument
		# button.connect("clicked", self.callback, "button 2")
		# Insert button 2 into the upper right quadrant of the table
		self.table.attach(label223,1,2,0,1)
		label223.show()
		# Create "Quit" button
		label224 = gtk.Label("Quit")
		# When the button is clicked, we call the main_quit function
		# and the program exits
		#button.connect("clicked", lambda w: gtk.main_quit())
		self.table.attach(label224,0,2,1,2)
		label224.show()
		self.table.show()
                
                
               
                
 


if __name__ == "__main__":
        hwg = HellowWorldGTK()
        gtk.main()

        
        getdata.cursor.close
        getdata.connection.close
        
        print "bye bye x"
